﻿; (function (global) {

    'use strict';

    global.UserOptions = function UserOptions() {
        this.timerVisible = false;
    }

    UserOptions.revive = function (data) {
        var inst = new UserOptions();
        inst.timerVisible = data.timerVisible;
        return inst;
    };

    UserOptions.prototype.toJSON = function () {
        return {
            _t: 'UserOptions',
            timerVisible: this.timerVisible
        };
    };

    UserOptions.current = new UserOptions();

    UserOptions.init = function () {
        EVENTBROKER.gameTopic.on(TOPIC_EVENTS.gameReady, UserOptions._onGameReady.bind(this));
        EVENTBROKER.gameTopic.on(TOPIC_EVENTS.gameOptionsChanged, UserOptions._onGameOptionsChanged.bind(this));
    };

    UserOptions._onGameReady = function (ev) {

        var userOptions = SaveManager.tryLoadItem("userOptions", UserOptions);
        if (!userOptions)
            userOptions = new UserOptions();

        EVENTBROKER.gameTopic.trigger(TOPIC_EVENTS.gameOptionsChanged, userOptions);
    };

    UserOptions._onGameOptionsChanged = function (ev, userOptions) {
        UserOptions.current = userOptions;
        SaveManager.saveItem("userOptions", userOptions);
    };

    UserOptions.init();

}(this));